<?php 
require_once("../include/conn.php");
//error_reporting(6143);
//dump($_POST);
if (isset($_POST['name'])) {
	$nname=$_POST['name'];
}
if (isset($_POST['id'])) {
	$id=$_POST['id'];
}
$table=$tb_dz;

$buid=$_POST["lanmu"]?$_POST["lanmu"]:0;

$title=trim($_POST["title"]);
$author=trim($_POST["author"]);
$tdate=trim($_POST["tdate"]);
$content=trim($_POST["content1"]);
$content=str_replace("'","\"",$content);
//$file = $_FILES["uploadfile"]["tmp_name"];
if($author!="" && $title!="" && $tdate!="" && $content!="" )	{
	
		if($_POST["action"] == "update"){				
			if(!empty($_POST["id"])){
				$delsql="delete from $tb_mp where bl_id ='$id'";//删除原来的滚动新闻图片
//				echo 'delsql='.$delsql;	
				mysql_db_query($db_name,$delsql);					
								
				$sql_dz="UPDATE `$table` SET ";
				$sql_dz.=" `title` = '$title',`tdate` = '$tdate',`content` = '$content',`author` = '$author', `buid`= '".$buid."'";	
				
				if(!empty($_POST["jian"])){
					$sql_dz.="  , `jian`= '1'";		
				}else{
					$sql_dz.="  , `jian`= '0'";	
				}									
				if(!empty($_POST["ishit"])){
					$sql_dz.="  , `ishit`= '1'";				
				}else{
					$sql_dz.=" , `ishit`= '0'";	
				}
				if(!empty($_POST["iszqkb"])){
					$sql_dz.="  , `iszqkb`= '1'";				
				}else{
					$sql_dz.="  , `iszqkb`= '0'";	
				}						
				$sql_dz.="  WHERE `id` = '$id'";					
//				echo  $sql_dz;					
				mysql_db_query($db_name,$sql_dz); 					
			
			}else{
				self("参数不全!","admin_index.php");
			}
		
		}else if($_POST["action"] == "add"){	
			
			$fieldnum="`title` , `author` , `content` , `tdate`, `buid`";			
			$contentnum="'$title', '$author', '$content', '$tdate', '$buid'";			
			
			if(!empty($_POST["jian"])){
				$fieldnum.=", `jian`";			
				$contentnum.=", '1'";				
			}else{
				$fieldnum.=", `jian`";			
				$contentnum.=", '0'";	
			}			
			
			if(!empty($_POST["ishit"])){
				$fieldnum.=", `ishit`";			
				$contentnum.=", '1'";				
			}else{
				$fieldnum.=", `ishit`";			
				$contentnum.=", '0'";	
			}
			if(!empty($_POST["iszqkb"])){
				$fieldnum.=", `iszqkb`";			
				$contentnum.=", '1' ";				
			}else{
				$fieldnum.=", `iszqkb`";			
				$contentnum.=", '0'";	
			}
			$sql_add="INSERT INTO $table ( ".$fieldnum.") VALUES (".$contentnum.")";			
//			echo $sql_add;					
			 mysql_db_query($db_name,$sql_add); 	
			 $id=mysql_insert_id();	
		}
		
		if (isset($_POST["pic"]) && strlen($_POST["pic"])>15) {
			$pic1=$_POST["pic"];
			$piclist=explode('|',$pic1);						
			foreach ($piclist as $pic) {
				if (is_pic($pic)) {
					if (empty($sqlbase)) {
						$sqlbase=insertpic('bl_id,url',$id.','.$pic);	
					}else {
						$sqlbase=insertpic('bl_id,url',$id.','.$pic,$sqlbase);	
					}
				}
			}						
			$sqlstartp="insert into `$tb_mp`  ";
			$sql=$sqlstartp.$sqlbase;
//			echo $sql;
			mysql_db_query($db_name,$sql);
		}			
		if(in_array($nname,array('3','4','9'))){
			self("操作已成功!","info_mange.php?name=$nname");			
		 } 
}
else{
	back("填写资料不完整！");
}?>